package org.wishwork.api.product.common.item.query;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.wishwork.api.ExtendBase;
import org.wishwork.exception.ExceptionEnum;
import org.wishwork.exception.JSTException;

import java.util.List;

/**
 * @description: 普通商品查询 按款查询
 * @author: WangYX
 * @create: 2022-04-11 11:10
 * @Version: 1.0.0
 **/
@EqualsAndHashCode
@Getter
@ToString
public class CommonProductItemQueryRequest extends ExtendBase {

    /**
     * 款式编码，与修改时间不能同时为空，最多20
     */
    private List<String> iIds;

    private CommonProductItemQueryRequest(Integer pageIndex, Integer pageSize,
                                          String modifiedBegin, String modifiedEnd,
                                          List<String> iIds) {
        super(pageIndex, pageSize, modifiedBegin, modifiedEnd);
        this.iIds = iIds;
    }

    @Override
    public Builder toBuilder() {
        return new Builder()
                .pageIndex(this.pageIndex)
                .pageSize(this.pageSize)
                .modifiedBegin(this.modifiedBegin)
                .modifiedEnd(this.modifiedEnd)
                .iIds(this.iIds);
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder extends ExtendBase.Builder<Builder, CommonProductItemQueryRequest> {

        private List<String> iIds;

        @Override
        public Builder modifiedBegin(String modifiedBegin) {
            this.modifiedBegin = modifiedBegin;
            return this;
        }

        @Override
        public Builder modifiedEnd(String modifiedEnd) {
            this.modifiedEnd = modifiedEnd;
            return this;
        }

        @Override
        public Builder pageIndex(Integer pageIndex) {
            this.pageIndex = pageIndex;
            return this;
        }

        @Override
        public Builder pageSize(Integer pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public Builder iIds(List<String> iIds) {
            if (iIds != null && iIds.size() > 0) {
                if (this.iIds.size() > 20) {
                    throw new JSTException(ExceptionEnum.USER_ERROR_A0420, "款式编码，与修改时间不能同时为空，最多20");
                }
            }
            this.iIds = iIds;
            return this;
        }

        @Override
        public CommonProductItemQueryRequest build() {
            this.pageIndex = this.pageIndex == null ? 1 : this.pageIndex < 0 ? 1 : this.pageIndex;
            this.pageSize = this.pageSize == null ? 30 : this.pageSize < 0 ? 30 : this.pageSize;
            if (this.iIds != null && this.iIds.size() <= 0) {
                keyIsEmptyTimeHandle(7);
            }
            modifiedTimeHandle(7);
            return new CommonProductItemQueryRequest(this.pageIndex, this.pageSize, this.modifiedBegin, this.modifiedEnd, this.iIds);
        }
    }

}
